package com.world.tg.controller;

import com.world.tg.result.JsonResult;
import com.world.tg.service.HomeService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/home")
@Api(tags = "首页模块")
@CrossOrigin("*")
public class HomeController implements EnvironmentAware {

    @Autowired
    private HomeService homeService;

    @GetMapping("/books")
    @ApiOperation("请求首页接口")
    @ApiImplicitParam(name = "currentPage",value = "当前页",required = true,paramType = "query")

    public JsonResult findHome(
            @RequestParam(value = "upPrice",required = false) Double upPrice ,
            @RequestParam(value = "downPrice",required = false) Double downPrice,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam Integer currentPage
    ){
        return homeService.findHome(downPrice,upPrice,name,currentPage);
    }

    private Environment environment = null;

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
        System.out.println(environment.getDefaultProfiles());
    }
}
